#include <iostream>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <math.h>
#include <algorithm>
using namespace std;

int search(vector<int>& nums, int target) {
    short start=0,end=nums.size()-1,mid;
    while(start<end){
        mid=(start+end)/2;
        if((nums[0]>target)^(nums[0]>nums[mid])^(nums[mid]<target))start = mid + 1;
        else end=mid;
    }
    return start==end&&nums[start]==target?start:-1;
}

int main(){
    vector<int>nums={4,5,6,7,0,1,2};
    cout<<search(nums,0)<<endl;
    return 0;
}